// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;
//import {globalMember} from "./global";

@ccclass
export default class NewClass extends cc.Component {

   
    faceLeft: boolean = true;

    //canmove: boolean = false;//控制
    
    faceUp: boolean = true; 

    dia: cc.Node = null;

    dialogScript: cc.Component = null;
   
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        cc.systemEvent.on('keydown',this.onKeyDown, this);
    }

    start () {

    }

    onKeyDown(evt: cc.Event.EventKeyboard){
        //if(globalMember.can_move){
            if(evt.keyCode == cc.macro.KEY.left){
                this.moveLeft();
            }
            if(evt.keyCode == cc.macro.KEY.right){
                this.moveRight();
            }
            if(evt.keyCode == cc.macro.KEY.up){
                this.moveUp();
            }
            if(evt.keyCode == cc.macro.KEY.down){
                this.moveDown();
            }
        //}
    }

    moveLeft(){

        this.move1();
    }
    moveRight(){
        this.faceLeft = false;
        this.move1();
        this.faceLeft = true;
       
    }
    moveUp(){
        this.move2();
    }
    moveDown(){
        this.faceUp = false;
        this.move2();
        this.faceUp = true;
    }

    move1(){
        if(this.faceLeft){
            this.node.x -= 10;
        }
        else{
            this.node.x += 10;
        }
        
    }
    move2(){
        if(this.faceUp){
            this.node.y += 10;
        }
        else{
            this.node.y -= 10;
        }
        
    }

    onCollisionEnter(other: cc.Collider, self: cc.Collider){
        cc.log("11111111111");
        //globalMember.can_move = false;
        this.dia = cc.find('Canvas/气泡框1');
        //this.dialogScript = this.dia.getComponent('StreetDia');
        this.dia.active = true;
        this.dia = cc.find('Canvas/提示板（棕色）');
        this.dia.active = false;
        this.dia = cc.find('Canvas/hero');
        this.dia.active = false;
        this.dia = cc.find('Canvas/npc');
        this.dia.active = false;
        this.dia = cc.find('Canvas/up');
        this.dia.active = false;
        this.dia = cc.find('Canvas/down');
        this.dia.active = false;
        this.dia = cc.find('Canvas/left');
        this.dia.active = false;
        this.dia = cc.find('Canvas/right');
        this.dia.active = false;
        //globalMember.can_move = true;
    }
    //控制can_move的真假从而引用到buttonCon中
    // can_moveCon(){
    //     globalMember.can_move = true;
    //     if(this.canmove){
    //         globalMember.can_move = false;
    //     }
    // }

     update (dt) {
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        cc.director.getCollisionManager().enabledDebugDraw = false;
        cc.director.getCollisionManager().enabledDrawBoundingBox = false;
     }
}
